/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License Version
 *  3 as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
 *  USA.
 */
#ifndef _ZONE_INTERFACE__H_
#define _ZONE_INTERFACE__H_

#include <optra/common/global.h>

#include <QSettings>

namespace Optra{

    class DB;
    class Proxy;
    class ZoneInfo;

    class SDK_EXPORT ZoneInterface : public QObject
    {
        Q_OBJECT
        Q_CLASSINFO("Version", "0.0.1")

        Q_ENUMS(Op::States)
        Q_PROPERTY(Op::States state READ state)
    public:

        ZoneInterface(QObject *parent = 0);
        virtual ~ZoneInterface();


         //Target common application interface


        /**
          * check if zone is ready to work
          */
        Op::States state()const;

        /**
          *Main zone
          */
        ZoneInterface* optra()const;


        /* Logger */
        void error(const QString& log);
        void critical(const QString& log);
        void warning(const QString& log);
        void info(const QString& log);

        void debug(const QString& log);
        void trace(const QString& log);


    signals:
        /**
          * Zone send this signal when is fully initialized and ready to work
          * Aplication or other zone can wait for this signal and launch depended tasks when zone will be ready
          */
        void zoneReady(QString name);




    protected:
        void updateState(Op::States state);


        /****************************************/

    public:
        void setProxy(Proxy* proxy);
        Proxy* proxy();


        virtual ZoneInfo* zoneInfo() = 0;


        QSettings& settings();
        void setSettings(QSettings* settings);

        QDir baseDir()const;
        void setBaseDir(const QDir& dir);

        DB* db();   
    public slots:
        virtual bool install();
        virtual bool initialize();
        virtual void launch();

        virtual void unload();        
    private:

        Proxy *proxy_;
        QDir base_;
        QSettings* settings_;
        DB *db_;
        Op::States state_;
    };

};

#endif /* _ZONE_INTERFACE__H_ */
